package de.hochschuletrier.bachelor.antfarm.states;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import de.hochschuletrier.bachelor.antfarm.control.ControlFrame;
import de.hochschuletrier.bachelor.antfarm.control.SimulationController;
import de.hochschuletrier.bachelor.antfarm.settings.Settings;
import de.hochschuletrier.bachelor.antfarm.world.World;

public class SimulationState extends AbstractState {
	private World world;
	private SimulationController controller;
	
	private boolean initialized;

	public SimulationState() {
		Settings.init();
		
		controller = new SimulationController();
	}

	@Override
	public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
	}

	@Override
	public int getID() {
		return 0;
	}

	@Override
	public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
		g.translate(Settings.getTranslateX(), Settings.getTranslateY());
		g.scale(Settings.getScale(), Settings.getScale());
		world.render(g, gc);
		g.resetTransform();
	}

	@Override
	public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
		controller.update(gc, delta);
		world.update(gc, delta);
	}

	@Override
	public void enter(GameContainer gc, StateBasedGame sbg) throws SlickException {
		if (!initialized) {
			world = new World();
			new ControlFrame(gc, world);
		}
	}

	@Override
	public void leave(GameContainer gc, StateBasedGame sbg) throws SlickException {
		// TODO Auto-generated method stub

	}
}
